package com.crane.oss.sports;

import java.util.Map;

import org.springframework.stereotype.Component;

import com.crane.common.framework.http.apache.HttpClientUtils;
import com.crane.common.framework.http.apache.HttpResult;
import com.crane.oss.xunfei.req.CheckHomeWorkReq;
import com.crane.oss.xunfei.req.CommentHomeWorkReq;
import com.crane.oss.xunfei.req.DeleteHomeWorkReq;
import com.crane.oss.xunfei.req.HomeWorkDetailReq;
import com.crane.oss.xunfei.req.PublishHomeWorkReq;
import com.crane.oss.xunfei.req.QueryHomeWorkListReq;
import com.crane.oss.xunfei.req.SubmitHomeWorkReq;
import com.crane.oss.xunfei.resp.ApiListResponse;
import com.crane.oss.xunfei.resp.ApiSingleResponse;
import com.crane.oss.xunfei.resp.HomeWorkDetailResp;
import com.crane.oss.xunfei.resp.HomeWorkListResp;
import com.fasterxml.jackson.core.type.TypeReference;

@Component
@SuppressWarnings("unchecked")
public class XunFeiHomeWorkApiService extends XunFeiApiService {

	/**
	 * 作业列表
	 * @param request
	 * @param sid
	 * @param did
	 * @param uid
	 * @return
	 */
    public ApiListResponse<HomeWorkListResp> getHomeWorkList(QueryHomeWorkListReq request, String sid, String did, String uid) {
    	Map<String, String> params = getStringStringMap(request, sid, did, uid);
        HttpResult httpResult=HttpClientUtils.get(xunFeiAppConfig.getUrl()+"/homework/info/list",params);
        if(httpResult.isSuccess()){
            ApiListResponse<HomeWorkListResp> response=httpResult.getDataObjectByJson(new TypeReference<ApiListResponse<HomeWorkListResp>>(){});
            return response;
        }
        return ApiListResponse.buildFailure();
    }

    /**
     * 发布/修改作业
     * @param request
     * @param sid
     * @param did
     * @param uid
     * @return
     */
    @SuppressWarnings("rawtypes")
	public ApiSingleResponse publishHomeWork(PublishHomeWorkReq request, String sid, String did, String uid) {
    	Map<String, String> params = getStringStringMap(request, sid, did, uid);
        HttpResult httpResult=HttpClientUtils.post(xunFeiAppConfig.getUrl()+"/homework/info/publish",params);
        if(httpResult.isSuccess()){
        	ApiSingleResponse response=httpResult.getDataObjectByJson(new TypeReference<ApiSingleResponse>(){});
            return response;
        }
        return ApiSingleResponse.buildFailure();
    }

    /**
     * 作业详情
     * @param request
     * @param sid
     * @param did
     * @param uid
     * @return
     */
    public ApiListResponse<HomeWorkDetailResp> getHomeWorkDetail(HomeWorkDetailReq request, String sid, String did, String uid) {
    	Map<String, String> params = getStringStringMap(request, sid, did, uid);
        HttpResult httpResult=HttpClientUtils.get(xunFeiAppConfig.getUrl()+"/homework/info/detail",params);
        if(httpResult.isSuccess()){
        	ApiListResponse<HomeWorkDetailResp> response=httpResult.getDataObjectByJson(new TypeReference<ApiListResponse<HomeWorkDetailResp>>(){});
            return response;
        }
        return ApiListResponse.buildFailure();
    }

    /**
     * 提交作业
     * @param request
     * @param sid
     * @param did
     * @param uid
     * @return
     */
	public ApiSingleResponse<String> submitHomeWork(SubmitHomeWorkReq request, String sid, String did, String uid) {
    	Map<String, String> params = getStringStringMap(request, sid, did, uid);
        HttpResult httpResult=HttpClientUtils.post(xunFeiAppConfig.getUrl()+"/homework/info/submit",params);
        if(httpResult.isSuccess()){
            ApiSingleResponse<String> response = httpResult.getDataObjectByJson(new TypeReference<ApiSingleResponse<String>>() {
            });
            return response;
        }
        return ApiSingleResponse.buildFailure();
    }

	/**
	 * 删除作业
	 * @param request
	 * @param sid
	 * @param did
	 * @param uid
	 * @return
	 */
    @SuppressWarnings("rawtypes")
	public ApiSingleResponse deleteHomeWork(DeleteHomeWorkReq request, String sid, String did, String uid) {
    	Map<String, String> params = getStringStringMap(request, sid, did, uid);
        HttpResult httpResult=HttpClientUtils.post(xunFeiAppConfig.getUrl()+"/homework/info/delete",params);
        if(httpResult.isSuccess()){
        	ApiSingleResponse response=httpResult.getDataObjectByJson(new TypeReference<ApiSingleResponse>(){});
            return response;
        }
        return ApiSingleResponse.buildFailure();
    }

    /**
     * 检查是否可以修改作业
     * @param request
     * @param sid
     * @param did
     * @param uid
     * @return
     */
    public ApiSingleResponse<String> checkHomeWork(CheckHomeWorkReq request, String sid, String did, String uid) {
    	Map<String, String> params = getStringStringMap(request, sid, did, uid);
        HttpResult httpResult=HttpClientUtils.post(xunFeiAppConfig.getUrl()+"/homework/info/corn/check",params);
        if(httpResult.isSuccess()){
        	ApiSingleResponse<String> response=httpResult.getDataObjectByJson(new TypeReference<ApiSingleResponse<String>>(){});
            return response;
        }
        return ApiSingleResponse.buildFailure();
    }

    /**
     * 老师批改作业
     * @param request
     * @param sid
     * @param did
     * @param uid
     * @return
     */
	public ApiSingleResponse<String> commentHomeWork(CommentHomeWorkReq request, String sid, String did, String uid) {
    	Map<String, String> params = getStringStringMap(request, sid, did, uid);
        HttpResult httpResult=HttpClientUtils.post(xunFeiAppConfig.getUrl()+"/homework/info/teacher/comment",params);
        if(httpResult.isSuccess()){
        	ApiSingleResponse<String> response=httpResult.getDataObjectByJson(new TypeReference<ApiSingleResponse<String>>(){});
            return response;
        }
        return ApiSingleResponse.buildFailure();
    }

    public static void main(String[] args) {
    	XunFeiHomeWorkApiService api = new XunFeiHomeWorkApiService();

//    	SubmitHomeWorkReq submitReq = new SubmitHomeWorkReq();
//    	submitReq.setHomeworkId("3fdcb94b306b47ef9ac72535d1c66fea");
//    	submitReq.setSubmitContent("完成的很不错");
//    	submitReq.setStudentId("6");
//    	System.out.println(api.submitHomeWork(submitReq, "87", null, "3"));

    	HomeWorkDetailReq DetailReq = new HomeWorkDetailReq();
    	DetailReq.setHomeworkId("a0e783abe2d34de79eb7e07a8f3c0017");
    	DetailReq.setClassId("1");
    	System.out.println(api.getHomeWorkDetail(DetailReq, "87", null, "3"));

//    	PublishHomeWorkReq publishRea = new PublishHomeWorkReq();
//    	publishRea.setTitle("1分钟跳绳");
//    	publishRea.setContext("跳绳比赛");
//    	publishRea.setSubmitTime(86400000l);
//    	publishRea.setCampusId("1");
//    	publishRea.setSectionId("2");//xd0:小学，xd1:初中，xd2:高中
//    	publishRea.setNj(1);
//    	publishRea.setClassId("1");
//    	publishRea.setClassType(1);//0 行政班 1分层班
//    	publishRea.setLoopRule(1);
//    	publishRea.setBeginTime(1651732200000l);
//    	publishRea.setEndTime(1652164200000l);
//    	publishRea.setReamrk("1");
//    	publishRea.setVideoUrl(null);
//    	publishRea.setPictureUrl(null);
//    	publishRea.setFileUrl(null);
//    	publishRea.setTeacherId("3");
//    	System.out.println(api.publishHomeWork(publishRea, "87", null, "3"));

//    	QueryHomeWorkListReq ListReq = new QueryHomeWorkListReq();
//    	ListReq.setBeginTime(1651630205000l);
//    	ListReq.setEndTime(1659686448000l);
//    	ListReq.setType(2);
//    	ListReq.setPage(1);
//    	ListReq.setLimit(40);
//    	System.out.println(api.getHomeWorkList(ListReq, "87", null, "3"));

//    	CheckHomeWorkReq request = new CheckHomeWorkReq();
//    	request.setId("3fdcb94b306b47ef9ac72535d1c66fea");
//    	System.out.println(api.checkHomeWork(request, "87", null, "3"));
    }

}
